{% extends "base.html" %}

{% block title %}用户排行榜{% endblock %}

{% block content %}
<div class="container py-4">
    <div class="card shadow-sm">
        <div class="card-header bg-transparent">
            <div class="d-flex justify-content-between align-items-center">
                <h4 class="mb-0">
                    <i class="bi bi-trophy-fill text-warning me-2"></i>
                    用户排行榜
                </h4>
                <span class="text-muted">共 {{ users|length }} 名用户</span>
            </div>
        </div>
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover mb-0">
                    <thead class="table-light">
                        <tr>
                            <th class="text-center" style="width: 80px">排名</th>
                            <th>用户</th>
                            <th class="text-center">积分</th>
                            <th class="text-center">烟蒂回收</th>
                            <th class="text-center">城市</th>
                            <th class="text-center">加入时间</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for user in users %}
                        <tr class="{% if user.id == current_user.id %}table-info{% endif %}">
                            <td class="text-center">
                                <span class="badge {% if loop.index == 1 %}bg-warning{% 
                                                   elif loop.index == 2 %}bg-secondary{% 
                                                   elif loop.index == 3 %}bg-bronze{% 
                                                   else %}bg-light text-dark{% endif %} border">
                                    {{ loop.index }}
                                </span>
                            </td>
                            <td>
                                <a href="{{ url_for('user_detail', user_id=user.id) }}" 
                                   class="text-decoration-none text-dark">
                                    <div class="d-flex align-items-center">
                                        {% if user.avatar_data %}
                                            <img src="{{ url_for('get_avatar', user_id=user.id) }}" 
                                                 class="rounded-circle me-2" 
                                                 alt="头像" 
                                                 style="width: 32px; height: 32px; object-fit: cover;">
                                        {% else %}
                                            <img src="{{ url_for('static', filename=user.avatar) }}" 
                                                 class="rounded-circle me-2" 
                                                 alt="头像" 
                                                 style="width: 32px; height: 32px; object-fit: cover;">
                                        {% endif %}
                                        <div>
                                            {{ user.username }}
                                            {% if user.id == current_user.id %}
                                                <span class="badge bg-info ms-1">我</span>
                                            {% endif %}
                                        </div>
                                    </div>
                                </a>
                            </td>
                            <td class="text-center">{{ user.points }}</td>
                            <td class="text-center">{{ user.cigarette_butts }}</td>
                            <td class="text-center">{{ user.city or '未设置' }}</td>
                            <td class="text-center">{{ user.created_at.strftime('%Y-%m-%d') }}</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<style>
.table > tbody > tr:hover {
    background-color: rgba(0, 123, 255, 0.05);
    cursor: pointer;
}
</style>
{% endblock %} 